from db_module import *
from google.appengine.api import users

def is_admin():
    return users.is_current_user_admin()

def check_is_admin(self, location):
    user = users.get_current_user()
    if users.is_current_user_admin()== False:
        self.redirect(location)

def check_user(self):
    user = users.get_current_user()
    if user:
        register = Register.gql("where username = :1", user.nickname())
        if register.count() <= 0:
            self.redirect('/reg')
        else:
            reg = register.get()
            self.response.out.write("Hello %s.<br />" % reg.nickname)
    else:
        self.redirect(users.create_login_url(self.request.uri))
        
        
def get_username():
    return users.get_current_user().nickname()